* Feb 7, 2022
* BIT 

** BIT data from https://investmentpolicy.unctad.org/international-investment-agreements/iia-mapping
** Coding Home and Host: In a given dyad, a state is labeled as a home if its GDP per capita (WDI, 2022) is greater than the other. 
* - When WDI is missing GDP per capita for one or both of the countries, other sources (IMF, OECD, and Global Economy). 

** COLONIAL TIES: mainly from Issues Correlates of War Colonial History Data. Based on it, countries are coded to have colonial ties if they share the common colonizer(s).
* - Also, Latin American states have been updated to reflect their Spanish colonial ties. South Korea has been updated to have a colonital tie with Japan.

** ISDS: coded as 1 if a given BIT specifies domestic court as the only means; 2 if BIT has other venues besides the domestic court; 
* 3 if BIT delegates the dispute settlement to one or more third parties including ICSID; and 4 if BIT specifies ICSID as the only means. 

*all isds variables (isds, isds1, isds2, domestic, icsid, uncitral, others) are from UNICTRAL.

* ISDS (0 if no isds measures at all; 1 if no delegation (domestic); 2 if some delegation + domestic;
*       3 if some delegation without domestic; 4 if delegation only to ICSID)

use bit022022, clear

gen isds=0 if none==1 
replace isds=1 if domestic==1 & none==0 & icsid==0 & uncitral==0 & others==0
replace isds=2 if domestic==1 & none==0 & icsid==1 & uncitral==0 & others==0
replace isds=2 if domestic==1 & none==0 & icsid==0 & uncitral==1 & others==0
replace isds=2 if domestic==1 & none==0 & icsid==0 & uncitral==0 & others==1
replace isds=2 if domestic==1 & none==0 & icsid==1 & uncitral==1 & others==0
replace isds=2 if domestic==1 & none==0 & icsid==1 & uncitral==0 & others==1
replace isds=2 if domestic==1 & none==0 & icsid==0 & uncitral==1 & others==1
replace isds=2 if domestic==1 & none==0 & icsid==1 & uncitral==1 & others==1
replace isds=3 if domestic==0 & none==0 & icsid==1 & uncitral==1 & others==0
replace isds=3 if domestic==0 & none==0 & icsid==0 & uncitral==1 & others==1
replace isds=3 if domestic==0 & none==0 & icsid==1 & uncitral==0 & others==1
replace isds=3 if domestic==0 & none==0 & icsid==1 & uncitral==1 & others==1
replace isds=3 if domestic==0 & none==0 & icsid==1 & uncitral==1 & others==0
replace isds=3 if domestic==0 & none==0 & icsid==0 & uncitral==1 & others==1
replace isds=3 if domestic==0 & none==0 & icsid==1 & uncitral==0 & others==1
replace isds=3 if domestic==0 & none==0 & icsid==0 & uncitral==1 & others==0
replace isds=3 if domestic==0 & none==0 & icsid==0 & uncitral==0 & others==1
replace isds=4 if domestic==0 & none==0 & icsid==1 & uncitral==0 & others==0

*binary isds delegation variable. 0 if no delegation (none or only domestic) and 1 otherwise
gen isdsdelbinary=0 if isds==0 | isds==1
replace isdsdelbinary=1 if isds==2|isds==3|isds==4

gen isdsdeldegree=1 if isds==2
gen isdsdeldegree=2 if isds==3
gen isdsdeldegree=3 if isds==4


****************MAIN MODEL*******************
*********************************************
*with binary dem vars - demhost and demhome
*with polity
eststo: quietly logit isdsdelbinary polity2host polity2home lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1, r
eststo: quietly logit isdsdelbinary demhost demhome lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1, r
esttab using binary.tex, label title(ISDS Delegation Binary)
estimates clear
eststo: quietly ologit isdsdeldegree polity2host polity2home lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1, r
eststo: quietly ologit isdsdeldegree demhost demhome lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1, r
esttab using deldegree.tex, label title(ISDS Delegation Degree)

**********predicted probabilities 2 ways
ologit isdsdeldegree demhost demhome lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1,r
margins, predict(outcome(1)) at(demhost=0) atmeans
* The probability of isdsdeldegree=1 holding other variables at means is 68.9% when host is not democratic.
margins, predict(outcome(1)) at(demhost=1) atmeans
* The probability of isdsdeldegree=1 holding other variables at means is 74.5% when host is democratic.

margins, predict(outcome(2)) at(demhost=0) atmeans
* The probability of isdsdeldegree=2 holding other variables at means is 19.5% when host is not democratic.
margins, predict(outcome(2)) at(demhost=1) atmeans
* The probability of isdsdeldegree=2 holding other variables at means is 16.4% when host is democratic.

margins, predict(outcome(3)) at(demhost=0) atmeans
* The probability of isdsdeldegree=3 holding other variables at means is 11.6% when host is not democratic.

margins, predict(outcome(3)) at(demhost=1) atmeans
* The probability of isdsdeldegree=3 holding other variables at means is 9.09% when host is democratic.

logit isdsdelbinary demhost demhome lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1, r
margins, at(demhost=0) atmeans 
*The probability of isdsdelbinary=0 is 95.6% when the host is not democratic
margins, at(demhost=1) atmeans  
*The probability of isdsdelbinary=1 98.6 when the host is democratic


********Binary 
*nondemo 
estsimp logit isdsdelbinary demhost demhome lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1, r
setx mean
setx demhost 0
simqi, prval(1) genpr(nondemprbi)

*demo
estsimp logit isdsdelbinary demhost demhome lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1, r
setx mean
setx demhost 1
simqi, prval(1) genpr(demprbi)
gen bidiff = demprbi/ nondemprbi
sumqi bidiff 
*1.03 times greater [1.01 to 1.05]

********delegation degree

estsimp ologit isdsdeldegree demhost demhome lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1,r
setx mean
setx demhost 0
simqi, prval(1) genpr(nondempr1)

estsimp ologit isdsdeldegree demhost demhome lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1,r
setx mean
setx demhost 1
simqi, prval(1) genpr(dempr1)
gen diff1=dempr1/nondempr1
sumqi diff1
*1.08 times [1.01 to 1.16]
estsimp ologit isdsdeldegree demhost demhome lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1,r
setx mean
setx demhost 0
simqi, prval(2) genpr(nondempr2)

estsimp ologit isdsdeldegree demhost demhome lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1,r
setx mean
setx demhost 1
simqi, prval(2) genpr(dempr2)
gen diff2=dempr2/nondempr2
sumqi diff2 
*0.85 times [0.71 to 1.0]

estsimp ologit isdsdeldegree demhost demhome lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1,r
setx mean
setx demhost 0
simqi, prval(3) genpr(nondempr3)

estsimp ologit isdsdeldegree demhost demhome lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1,r
setx mean
setx demhost 1
simqi, prval(3) genpr(dempr3)
gen diff3=dempr3/nondempr3
sumqi diff3
estimates clear
*0.78 times [0.60 to 0.99]


***********robustness check************

***create year variables for years with frequent BITs
tab year, sort
*create year variables for years with more than 60 BITs - mostly for years after the fall of USSR and the onset of Euro zone
local nyear "1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004"
foreach n in `nyear'{
		gen y`n'=1 if year==`n'
		replace y`n'=0 if year!=`n'
		}


***create country variables for home states with frequent BITs
tab homecn, sort
*create variables for home states with more than 40 BITs 
local hstat "2 20 200 210 220 225 230 235 255 305 316 325 375 380 390 640 696 732"
foreach val in `hstat'{
	gen v`val'=1 if homecn==`val'
	replace v`val'=0 if homecn!=`val'
}


gen v`val'=1 if homecn==`val'
replace v`val'=0 if homecn!=`val'
}


estimates clear
	eststo: quietly ologit isdsdeldegree demhost demhome lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1 v2-v732 y1991-y2004,r

eststo: quietly ologit isdsdeldegree polity2host polity2home lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1 v2-v732 y1991-y2004,r
esttab using robust.tex, label title(ISDS Delegation Degree with State and Year Variables)
estimates clear


*histogram for types of isds in BITs with frequent home states
keep if homecn==2|homecn==20|homecn==200|homecn==210|homecn==220|homecn==225|homecn==235|homecn==230|homecn==255|homecn==305|homecn==316|homecn==325|homecn==375|homecn==380|homecn==390|homecn==640|homecn==696|homecn==732
keep if homecn==2| homecn==20|homecn==200|homecn==210|homecn==220|homecn==225|homecn==230|homecn==235|homecn==255|homecn==305|homecn==316|homecn==325|homecn==375|homecn==380| homecn==390|homecn==640|homecn==696|homecn==732
twoway hist, by(homecn) discrete 

eststo: quietly ologit isdsdeldegree polity2host polity2home lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1 v2-v732 y1991-y2004,r
eststo: quietly ologit isdsdeldegree demhost demhome lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1 v2-v732 y1991-y2004,r
esttab using appendix.tex, label title(ISDS Delegation Degree with State and Year Variables - BITs with 18 home states only)



estimates clear
eststo: quietly ologit isdsdelnew polity2host polity2home lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1 if isds==2|isds==3|isds==4, r
eststo: quietly ologit isdsdelnew demhost demhome lnland lnrenthost lnfreshost fdihost lnpophost lngrowth lnopenness lndebt colties atopally1 if isds==2|isds==3|isds==4, r
esttab using appendix.tex, label title(Appendix: Logit Regression with an Alternative Dependent Variable)

estimates clear
